import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../../atom/config';
interface Message {
	filter: {
		exam_name: string,
		pn: number
	};
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const query = complex_query(action_id, session_id, systemid);
	const dt = await query
		// 添加字段
		.add_field('exam_management', 'exam_id', 'exam_id')
		.add_field('exam_management', 'exam_name', 'exam_name')
		.add_field('exam_management', 'exam_time', 'exam_time')
		.add_field('exam_management', 'examination_category', 'examination_category')
		// 模糊查询
		.where_like('exam_management', 'exam_name', '%' + message.filter.exam_name + '%')
		.page(20, message.filter.pn)
		.exec();

	const c = await query
		// 添加字段
		.add_field('exam_management', 'exam_id', 'exam_id')
		.add_field('exam_management', 'exam_name', 'exam_name')
		.add_field('exam_management', 'exam_time', 'exam_time')
		.add_field('exam_management', 'examination_category', 'examination_category')
		// 模糊查询
		.where_like('exam_management', 'exam_name', '%' + message.filter.exam_name + '%')
		.exec();
	return { dt, c };
}
